﻿using System;
using System.Collections.Generic;
using HiTeachers.Data.Manager;
using HiTeachers.Entities;
using HiTeachers.Interfaces;
using HiTeachers.Services.Exceptions;

namespace HiTeachers.Services
{
    public class StudentRequestServices
    {
        //private static readonly IStudentRequestDao StdRequestDao = NHibernateDaoFactory.Instance.GetDao<IStudentRequestDao>("studentRequest");
        private static readonly IStudentRequestDao StdRequestDao = NHibernateDaoFactory.Instance.GetStudentRequestDao();

        public static StudentRequest GetById(Guid itemId)
        {
            return StdRequestDao.GetById(itemId, false);
        }

        public static IList<StudentRequest> GetRelationStdRequests(Guid guid, DateTime aroundDate, int maxItem)
        {
            return StdRequestDao.GetRelationStdRequests(guid, aroundDate, maxItem);
        }

        public static int TotalVerifiedRequest()
        {
            return StdRequestDao.TotalVerifiedRequest();
        }

        public static IList<StudentRequest> GetVerifiedRequest(int maxResult, int startRowIndex)
        {
            return StdRequestDao.GetVerifiedRequest(maxResult, startRowIndex);
        }

        #region Adjustment Methods
        public static StudentRequest SaveOrUpdate(StudentRequest studentRequest)
        {
            if (Guid.Empty.Equals(studentRequest.ID))
            {
                if (LoggerEmailServices.IsExistEmail(studentRequest.Email, EmailType.Lock))
                    throw new EmailAlreadyLockException(string.Format("{0} is already lock!", studentRequest.Email));

                StdRequestDao.Save(studentRequest);
            }
            else
                StdRequestDao.SaveOrUpdate(studentRequest);

            return studentRequest;
        }

        public static void Delete(Guid itemId)
        {
            StudentRequest studentRequest = StdRequestDao.GetById(itemId, false);
            StdRequestDao.Delete(studentRequest);
        }

        public static void Delete(StudentRequest studentRequest)
        {
            StdRequestDao.Delete(studentRequest);
        }
        #endregion

        #region Selection Methods
        public static int TotalNumberOfStudentRequest(int reviewStatus)
        {
            return Convert.ToInt32(StdRequestDao.TotalNumberOfStudentRequest(reviewStatus));
        }

        public static IList<StudentRequest> GetStudentRequests(int reviewStatus)
        {
            return StdRequestDao.GetStudentRequests(reviewStatus);
        }

        public static IList<StudentRequest> GetStudentRequests(int reviewStatus, int maximumRows, int startRowIndex)
        {
            return StdRequestDao.GetStudentRequests(reviewStatus, maximumRows, startRowIndex);
        }
        #endregion
    }
}
